import { createRouter, createWebHistory } from 'vue-router'
import login from "@/views/Login/index.vue";
import Layout from "@/views/Layout/index.vue";
import Home from "@/views/Home/index.vue";
import Category from "@/views/Category/index.vue";
import SubCategory from "@/views/SubCategory/index.vue";
import Detail from '@/views/Detail/index.vue';
import CartList from '@/views/CartList/index.vue';
import CheckOut from '@/views/CheckOut/index.vue';
import Pay from '@/views/Pay/index.vue';
import payback from '@/views/Pay/payback.vue';
import Member from '@/views/Member/index.vue';
import UserInfo from '@/views/Member/components/UserInfo.vue';
import UserOrder from '@/views/Member/components/UserOrder.vue';

import MapView from '@/views/MapView/index.vue';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: Layout,
      children: [{
        name: 'home',
        path: '',
        component: Home
      },{
        name: 'category',
        path: 'category/:id',
        component: Category,
      },{
        name: 'subcategory',
        path: 'category/sub/:id',
        component: SubCategory
      },{
        name: 'detail',
        path: 'detail/:id',
        component: Detail
      },{
        name: 'cartlist',
        path: '/cartlist',
        component: CartList
      },{
        name: 'checkout',
        path: '/checkout',
        component: CheckOut
      },{
        name: 'pay',
        path: '/pay',
        component: Pay
      },{
        path: 'payback',
        component: payback
      },{
        path: 'member',
        component: Member,
        children: [{
          path: 'user',
          component: UserInfo
        },{
          path: 'order',
          component: UserOrder
        }]
      }]
    },{
      path: '/login',
      name: 'login',
      component: login
    },{
      path: '/map',
      component: MapView
    }
    
  ],
  // 路由滚轮定制。切换页面后滚轮在顶部
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
